(() => {
  class Exception {
    constructor ($mdToast) {
      this.$mdToast = $mdToast;
    }
    handle (error) {
      let msg = '';
      if (error.errcode) {
        msg = error.errmsg;
      }
      else if (error.status) {
        msg = error.statusText;
      }
      else {
        msg = '发生未知错误';
      }
      this.$mdToast.show(
        this.$mdToast.simple()
          .textContent(msg)
          .position('right bottom')
          .hideDelay(5000)
      ); 
    }

  }
  angular.module('app').factory('$exception', ['$mdToast', ($mdToast) => new Exception($mdToast)]);
})()